import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author pinker on 2018/4/5
 */
public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int m = in.nextInt();
    int n = in.nextInt();
    char[][] users = new char[m][3];
    in.nextLine();
    for (int i = 0; i < m; i++) {
      String line = in.nextLine();
      users[i] = line.replaceAll(" ", "").toCharArray();
    }
    char[] primary = new char[m];
    for (int i = 0; i < m; i++) {
      primary[i] = users[i][0];
    }
    String prim = new String(primary);
    String result = "";
    for (int i = 0; i < m; i++) {
      int num = getNum(users[i]);
      int sum = num;
      for (int j = 1; j < num + 1; j++) {
        char ch = users[i][j];
        int index = prim.indexOf(ch);
        if (index > 0) {
          sum += getNum(users[index]);
        }
      }
      if (sum >= n) {
        result += users[i][0] + " ";
      }
    }
    System.out.println(result.trim());
  }

  private static int getNum(char[] user) {
    for (int i = 1; i < 3; i++) {
      if (user[i] == '*') {
        return i - 1;
      }
    }
    return 2;
  }

  private static long constructSongListMethod(int k, int a, int x, int b, int y) {
    long count = 0;
    for (int i = 1; i <= (k / a) && i <= x; i++) {
      int other = k - i * a;
      if (other > 0) {
        if (other % b == 0) {
          int j = other / b;
          count += (getProduct(x - i + 1, x) * getProduct(y - j + 1, y)) / (getProduct(1, i) * getProduct(1, j));
        }
      } else if (other == 0) {
        count += getProduct(x - i + 1, x) / getProduct(1, i);
      } else
        break;
    }
    if (k % b == 0) {
      count += getProduct(y - (k / b) + 1, y) / getProduct(1, k / b);
    }
    return count % 1000000007L;
  }

  static long getProduct(int start, int end) {
    if (start == 0) {
      return 0;
    }
    long result = 1;
    for (int i = start; i <= end; i++) {
      result *= start;
    }
    return result;
  }


  private static long getSum(int n, int m) {
    long sum1 = 0;//+数
    long sum2 = 0;//-数
    int times = n / (2 * m);
    for (int i = 1; i <= times; i++) {
      sum1 += m * ((4 * i - 1) * m + 1) / 2;
      sum2 += m * ((4 * i - 3) * m + 1) / 2;
    }
    return sum1 - sum2;
  }

  public boolean isPrimeNumber(int num) {
    if (num == 2) return true;//2特殊处理
    if (num < 2 || num % 2 == 0) return false;//识别小于2的数和偶数
    for (int i = 3; i <= Math.sqrt(num); i += 2) {
      if (num % i == 0) {//识别被奇数整除
        return false;
      }
    }
    return true;
  }

  public static void quickSort(int[] a) {
    if (a.length > 0) {
      quickSort(a, 0, a.length - 1);
    }
  }

  private static void quickSort(int[] a, int low, int high) {
    //1,找到递归算法的出口
    if (low > high) {
      return;
    }
    //2, 存
    int i = low;
    int j = high;
    //3,key
    int key = a[low];
    //4，完成一趟排序
    while (i < j) {
      //4.1 ，从右往左找到第一个小于key的数
      while (i < j && a[j] > key) {
        j--;
      }
      // 4.2 从左往右找到第一个大于key的数
      while (i < j && a[i] <= key) {
        i++;
      }
      //4.3 交换
      if (i < j) {
        int p = a[i];
        a[i] = a[j];
        a[j] = p;
      }
    }
    // 4.4，调整key的位置
    int p = a[i];
    a[i] = a[low];
    a[low] = p;
    //5, 对key左边的数快排
    quickSort(a, low, i - 1);
    //6, 对key右边的数快排
    quickSort(a, i + 1, high);
  }
}
